import 'package:flutter/material.dart';

/* 在给定的时间段内对齐其子组件的动画小部件 */
class AlignStatic extends StatefulWidget {
  const AlignStatic({super.key});

  @override
  State<AlignStatic> createState() => _AlignStaticState();
}

class _AlignStaticState extends State<AlignStatic> {
  Alignment _alignment = Alignment.topLeft;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      height: 300,
      decoration: BoxDecoration(
        border: Border.all(color: Colors.black, width: 1),
        borderRadius: BorderRadius.circular(8)
      ),
      child: Column(
        children: [
          ElevatedButton(
            onPressed: () {
              setState(() {
                _alignment = _alignment == Alignment.topLeft ? Alignment.bottomRight : Alignment.topLeft;
              });
            },
            child: Text('切换 Alignment'),
          ),
          AnimatedAlign(
            alignment: _alignment,
            duration: const Duration(seconds: 1),
            curve: Curves.easeInOut,
            child: Container(
              width: 50,
              height: 50,
              color: Colors.amber[200]
            ),
          )
        ],
      ),
    );
  }
}